//
//  PCDUpdateSessionPlugin.m
//  PCDBankSix
//
//  Created by 克里斯龙 on 2023/9/23.
//

#import "PCDUpdateSessionPlugin.h"
#import "PCDLoginModel.h"
@implementation PCDUpdateSessionPlugin
- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback{
    //
    NSDictionary *dict = (NSDictionary *)data;
    NSString *strCallback = dict[@"success"];
    NSString *failCallback = dict[@"fail"];
    [PCDLoginModel.shareInstance updateUserSessionWithCompleteBlock:^(BOOL success, id  _Nonnull session) {
        if (!success) {
            [PCDUtil toastMessage:@"刷新session失败"];
            evaluateJavaScriptOnMainThread(self, failCallback, @"");
            return;
        }
        PCDLoginSession * userInfo = session;
        [PCDUtil saveLoginSession:userInfo];
        //存储性别(A1升A2后,退出app,二次登录页面头像问题)
        PCDLoginSession *new_session = [PCDUtil loginSession];
        [PCDDataStorageMangerGet() setCacheUDString:new_session.gender forKey:kUserGender];
        evaluateJavaScriptOnMainThread(self, strCallback, @"");
    }];
}
@end
